package com.example.bookkeepingelf.business.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

import com.example.bookkeepingelf.R;
import com.example.bookkeepingelf.business.database.AppDatabase;

/**
 * 账本管理活动
 */
public class AccountBookManageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_book_manage);

        AppDatabase database = AppDatabase.getDatabase(this);

        replaceFrameLayout(R.id.frame_layout_account_book_manage_title, new AccountBookManageListTitleFragment());
        replaceFrameLayout(R.id.frame_layout_account_book_manage_content, new AccountBookManageListContentFragment(database));
    }

    private void replaceFrameLayout(int fragmentLayoutId, Fragment fragment) {
        // 替换fragment
        //1、获取fragment管理器
        FragmentManager fragmentManager = getSupportFragmentManager();
        //2、开启事务
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        //3、替换fragment
        transaction.replace(fragmentLayoutId, fragment);
        //4、放入返回栈
//        transaction.addToBackStack(null);
        //5、提交事务
        transaction.commit();
    }
}